<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head :: head"></head>
<body>
<div id="wrapper">
    <div id="sidebar-wrapper" th:replace="fragments/nav :: nav"></div>
    <div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <h1>Restore Redis Data:</h1>
                    <form id="queryForm" method="post">
                        <fieldset>

                            <div class="form-group">
                                <label class="control-label" for="path">Full Path to Backup file:</label><br/>
                                <div>
                                    <input id="path" name="path" type="text"
                                           placeholder="Enter full path to redis json dump" class="form-control input-md"
                                           size="25" th:required="true" th:autofocus="true"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <input id="submit" type="submit" class="btn btn-success" value="Restore"/>
                            </div>

                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- save confirmation -->
<div id="saveConfirmModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-body">
                <p id="saveConfirmModalCode">Are you sure? this is going to stop all running jobs if any!</p>
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal" class="btn btn-primary" id="saveConfirmModalYes">Yes
                </button>
                <button type="button" data-dismiss="modal" class="btn" id="saveConfirmModalNo">No</button>
            </div>
        </div>
    </div>
</div>
<script>

/*<![CDATA[*/
    $(document).ready(function () {
        $("#queryForm").submit(function (e) {
            e.preventDefault();
            $('#saveConfirmModalCode').html();
            $('#saveConfirmModal').modal('show');
        });
    });

    $("#saveConfirmModalYes").click(function () {
        var data = {};
        data.path = $('#path').val();
        $.ajax({
            type: 'POST',
            url: '/Debug/Restore',
            data: JSON.stringify(data),
            contentType: "application/json",
            dataType: 'text',
            success: function (response) {
                if ($.isEmptyObject(response)) {
                    showWarningMessage("Something went wrong! Try again.");
                } else {
                    showInfoMessage("Redis data ingested successfully!");
                    //setTimeout(function () {
                    //    window.location.href = '/';
                    //}, 1000);
                }
            },
            error: ajaxMessage
        });
    });
/*]]>*/
</script>
</body>
</html>
